package com.study.servlet;


import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.HandlesTypes;
import java.util.EnumSet;
import java.util.Set;

/**
 * @Description :
 * @Version : V1.0.0
 * @Date : 2022/9/19 20:56
 */
@HandlesTypes(HelloService.class)
public class MyServletContainerInitializer implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext sc) throws ServletException {
        System.out.println("MyServletContainerInitializer.onStartup ...");
        final ServletRegistration.Dynamic myServlet = sc.addServlet("myServlet", MyServlet.class);
        myServlet.addMapping("/hello");
        final FilterRegistration.Dynamic myFilter = sc.addFilter("myFilter", MyFilter.class);
        myFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true,"/*");
        sc.addListener(MyListener.class);
    }
}
